package com.chcit.custom;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TextView;

import com.chcit.custom.view.spinner.DropDownMenu;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;

import butterknife.BindView;
import butterknife.ButterKnife;

public class DropDownActivity extends AppCompatActivity {

    @BindView(R.id.pr_inventory_dropDownMenu)
    DropDownMenu mDropDownMenu;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_drop_down);
        ButterKnife.bind(this);
        initDropDownMenu();

    }
    private void initDropDownMenu() {
        final List<View> popupViews = new ArrayList<>();

        //供应商选择
        final ListView wareView = new ListView(this);
        List<String> bpartners = Arrays.asList("2313","2313213213");

        final GirdDropDownAdapter<String> bpartnerAdapter = new GirdDropDownAdapter<String>(this, bpartners);
        wareView.setDividerHeight(0);
        wareView.setAdapter(bpartnerAdapter);
        wareView.setOnItemClickListener((parent, view, position, id) -> {
            bpartnerAdapter.setCheckItem(position);
            ((TextView)mDropDownMenu.getTabView(0)).setTextColor(Color.RED);
            mDropDownMenu.closeMenu();
        });

        //存货状态
        final ListView dateView =  new ListView(this);

        final List<String> status = Arrays.asList("在库","不在库");
        final GirdDropDownAdapter<String> dateAdapter = new GirdDropDownAdapter<String>(this, status);
        dateView.setDividerHeight(0);
        dateView.setAdapter(dateAdapter);
        dateView.setOnItemClickListener((parent, view, position, id) -> {
            dateAdapter.setCheckItem(position);
            ((TextView)mDropDownMenu.getTabView(2)).setTextColor(Color.BLUE);
            mDropDownMenu.closeMenu();
        });
        popupViews.add(wareView);
        popupViews.add(dateView);
        final TextView contentView = new TextView(this);
        contentView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
        contentView.setText("");
        //contentView.setBackgroundColor(getResources().getColor(R.color.gray));
        contentView.setGravity(Gravity.CENTER);
        contentView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 20);
        final List<String> list = Arrays.asList("菜单一","菜单二");
        mDropDownMenu.setDropDownMenu(list, popupViews, contentView);

    }
}
